package com.dreamlin.app.widget

import android.content.Context
import android.graphics.*
import android.util.AttributeSet
import androidx.constraintlayout.widget.ConstraintLayout
import com.dreamlin.app.common.dp2px

class LoginFrameView(context: Context?, attrs: AttributeSet?) : ConstraintLayout(context!!, attrs) {

    private val paint: Paint = Paint(Paint.ANTI_ALIAS_FLAG)
    private val path = Path()

    init {
        paint.color = Color.WHITE
        paint.textSize = 24f.dp2px()
    }

    override fun onDraw(canvas: Canvas?) {

    }

    override fun dispatchDraw(canvas: Canvas?) {
        val triangleHeight = 4.5f.dp2px()
        val triangleWidth = 9f.dp2px()
        val x = (0.0967 * width).toFloat()
        path.moveTo(x, triangleHeight)
        path.lineTo(x + triangleWidth / 2, 0f)
        path.lineTo(x + triangleWidth, triangleHeight)
        path.close()
        canvas?.drawPath(path, paint)
        val rectf = RectF(
            0f, triangleHeight - 1f,
            width.toFloat(), height.toFloat()
        )
        canvas?.drawRoundRect(rectf, 10f.dp2px(), 10f.dp2px(), paint)
        super.dispatchDraw(canvas)
    }

}